package com.dd.filter;


import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class EncodeFilter implements Filter {

	private FilterConfig filterConfig;

	//private String encoding = "utf-8";

	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
		//this.encoding = filterConfig.getInitParameter("encoding");
	}

	public void doFilter(ServletRequest srequest, ServletResponse sresponse,
			FilterChain chain) throws IOException, ServletException {
		try {
			HttpServletRequest request = (HttpServletRequest) srequest;
			request.setCharacterEncoding("UTF-8");
			chain.doFilter(srequest, sresponse);
		} catch (ServletException sx) {
			filterConfig.getServletContext().log(sx.getMessage());
		} catch (IOException iox) {
			filterConfig.getServletContext().log(iox.getMessage());
		}
	}
	public void destroy() {
		filterConfig = null;
		//encoding = null;
	}

}


